from mcp.server.fastmcp import FastMCP
import math

mcp = FastMCP("Lyrics Recognition Service")

@mcp.tool()
async def recognize_song_by_lyrics(lyrics: str) -> dict:
    """
    通过歌词识别歌曲
    
    Args:
        lyrics: 输入的歌词片段
        
    Returns:
        包含歌曲信息的字典，格式为:
        {
            "title": "歌曲名称",
            "artist": "艺术家",
            "album": "专辑",
            "release_year": 发行年份,
            "lyrics": "完整歌词"
        }
    """
    # 歌曲数据库
    songs_db = {
        "爱我还是他": {
            "title": "爱我还是他",
            "artist": "陶喆",
            "album": "太平盛世",
            "release_year": 2005,
            "lyrics": "是不是真的他有比我好\n你为谁在挣扎\n你爱我还是他\n就说出你想说的真心话\n你到底要跟我还是他\n爱我还是他\n就说出你想说的真心话\n爱我还是他"
        },
        "晴天": {
            "title": "晴天",
            "artist": "周杰伦",
            "album": "叶惠美",
            "release_year": 2003,
            "lyrics": "故事的小黄花\n从出生那年就飘着\n童年的荡秋千\n随记忆一直晃到现在\n..."
        }
    }
    
    # 根据歌词片段匹配歌曲
    for song in songs_db.values():
        if lyrics in song["lyrics"]:
            return song
            
    return {
        "title": "未识别歌曲",
        "artist": "未知",
        "album": "未知",
        "release_year": 0,
        "lyrics": "未找到匹配的完整歌词"
    }

if __name__ == "__main__":
    mcp.run(transport="stdio")